/**
 * Description: SystemAnnouncementServiceImpl.java
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0  Mar 29, 2009 12:36:55 PM 李萌（neolimeng@gmail.com）created
 */
package org.paradise.dms.services.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.paradise.dms.dao.impl.SystemAnnouncementDAOImpl;
import org.paradise.dms.pojo.SystemAnnouncement;
import org.paradise.dms.services.SystemAnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 Mar 29, 2009 12:36:55 PM 李萌（neolimeng@gmail.com）created
 */
@Service
public class SystemAnnouncementServiceImpl implements SystemAnnouncementService {

	private static Logger log = Logger.getLogger(SystemAnnouncementServiceImpl.class);
	@Autowired
	@Qualifier("systemAnnouncementDAOImpl")
	private SystemAnnouncementDAOImpl systemAnnouncementDaoImpl;
	SystemAnnouncement sa;
	List<SystemAnnouncement> lsa;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.paradise.dms.services.SystemAnnouncementService#deleteSystemAnnouncement(int)
	 */
	public boolean deleteSystemAnnouncement(int systemannouncementid) {
		try {
			this.systemAnnouncementDaoImpl
					.deleteSystemAnnouncement(systemannouncementid);
			log.info("DMS_info_根据公告ID删除公告，成功！！ID值为："+systemannouncementid);
			return true;
		} catch (Exception e) {
			log.error("DMS_error_根据公告ID删除公告，失败！！ID值为："+systemannouncementid);
			e.printStackTrace();
			return false;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.paradise.dms.services.SystemAnnouncementService#getSystemAnnouncement(int)
	 */
	public SystemAnnouncement getSystemAnnouncement(int systemannouncementid) {
		try {
			sa=this.systemAnnouncementDaoImpl
					.getSystemAnnouncement(systemannouncementid);
			log.info("DMS_info_根据ID取得公告，成功！！ID值为："+systemannouncementid);
			return sa;
		} catch (Exception e) {
			log.error("DMS_error_根据ID取得公告，失败！！ID值为："+systemannouncementid);
			e.printStackTrace();
			return null;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.paradise.dms.services.SystemAnnouncementService#insertSystemAnnouncement(org.paradise.dms.pojo.SystemAnnouncement)
	 */
	public boolean insertSystemAnnouncement(
			SystemAnnouncement systemannouncement) {
		try {
			this.systemAnnouncementDaoImpl
					.insertSystemAnnouncement(systemannouncement);
			log.info("DMS_info_插入公告，成功！！公告标题是："+systemannouncement.getSystemannouncementtitle());
			return true;
		} catch (Exception e) {
			log.error("DMS_error_插入公告，失败！！");
			e.printStackTrace();
			return false;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.paradise.dms.services.SystemAnnouncementService#updateSystemAnnouncement(org.paradise.dms.pojo.SystemAnnouncement)
	 */
	public boolean updateSystemAnnouncement(
			SystemAnnouncement systemannouncement) {
		try {
			this.systemAnnouncementDaoImpl
					.updateSystemAnnouncement(systemannouncement);
			log.info("DMS_info_更新公告，成功！！新的公告标题是："+systemannouncement.getSystemannouncementtitle());
			return true;
		} catch (Exception e) {
			log.error("DMS_error_更新公告，失败！！");
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * @return the systemAnnouncementDaoImpl
	 */
	public SystemAnnouncementDAOImpl getSystemAnnouncementDaoImpl() {
		return systemAnnouncementDaoImpl;
	}

	/**
	 * @param systemAnnouncementDaoImpl
	 *            the systemAnnouncementDaoImpl to set
	 */
	public void setSystemAnnouncementDaoImpl(
			SystemAnnouncementDAOImpl systemAnnouncementDaoImpl) {
		this.systemAnnouncementDaoImpl = systemAnnouncementDaoImpl;
	}

	public List<SystemAnnouncement> getAllSystemAnnouncement() {
		try {
			lsa=this.systemAnnouncementDaoImpl.getAllSystemAnnouncement();
			log.info("DMS_info_取得所有公告，成功！！共有 "+lsa.size()+"条。");
			return lsa;
		} catch (Exception e) {
			log.error("DMS_error_取得所有公告，失败！！");
			e.printStackTrace();
			return null;
		}
	}

	public int getAllRows() {
		return this.systemAnnouncementDaoImpl.getAllRows();
	}

	public List<SystemAnnouncement> listAllSystemAnnouncement(int pageSize,
			int startRow) {
		try{
			lsa=this.systemAnnouncementDaoImpl.listAllSystemAnnouncement(pageSize, startRow);
			log.info("DMS_info_分页取得所有公告，成功！！本次读取" + pageSize + "条，起始条为第"
					+ startRow + "条");
			return lsa;
		}catch(Exception e){
			log.error("DMS_error_分页取得所有公告，失败！！");
			e.printStackTrace();
			return null;
		}
	}

	public List<SystemAnnouncement> getLsa() {
		return lsa;
	}

	public void setLsa(List<SystemAnnouncement> lsa) {
		this.lsa = lsa;
	}

	public SystemAnnouncement getSa() {
		return sa;
	}

	public void setSa(SystemAnnouncement sa) {
		this.sa = sa;
	}

}
